﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.ComponentModel;
using System.Threading;
using System.Windows.Media.Media3D;

namespace DXApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class LoginWindow : System.Windows.Window,IDisposable
    {
        BackgroundWorker worker;
        public LoginWindow()
        {
            InitializeComponent();
            worker = new BackgroundWorker();
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.DoWork += worker_DoWork;
        }

        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
           
                Thread.Sleep(1000);
                e.Result = true;
           
        }

        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                bool b = (bool)e.Result;
                if (b)
                {
                    MainWindow main = new MainWindow();
                    main.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("err3:" + ex.Message);
            }
        }
        private void DXWindow_Loaded(object sender, RoutedEventArgs e)
        {
            List<string> list = new List<string>();
            list.Add("376720513");
            list.Add("123456555");
            cboNumber.ItemsSource = list;
            cboNumber.SelectedIndex = 0;

        }

        private void DXWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //窗体可拖动
            this.DragMove();
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            
                txtPwd.Visibility = Visibility.Hidden;
                cboNumber.Visibility = Visibility.Hidden;
                chkRememberMe.Visibility = Visibility.Hidden;
                chkAutoLogin.Visibility = Visibility.Hidden;
                lblRegister.Visibility = Visibility.Hidden;
                lblFoundCode.Visibility = Visibility.Hidden;
                btnLogin.Content = "正在登录..";
                DoubleAnimation daX = new DoubleAnimation();
                DoubleAnimation daY = new DoubleAnimation();
                daX.To = 150;
                Duration dur = new Duration(TimeSpan.FromMilliseconds(500));
                daX.Duration = dur;
                daY.Duration = dur;
                tt.BeginAnimation(TranslateTransform.XProperty, daX);
                tt.BeginAnimation(TranslateTransform.YProperty, daY);
                if (!worker.IsBusy)
                {
                    worker.RunWorkerAsync();
                }
            
         
        }

        private void imgClose_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }

        private void imgMiniSize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void imgReverse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ////reverse
            gridFrontPage.Visibility = Visibility.Hidden;
            gridBackPage.Visibility = Visibility.Visible;
            Storyboard sbto = Resources["SBBackTrans"] as Storyboard;
            sbto.Begin(this);
            
            
            
        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            gridBackPage.Visibility = Visibility.Hidden;
            gridFrontPage.Visibility = Visibility.Visible;
            Storyboard sbto = Resources["SBFrontTrans"] as Storyboard;
            sbto.Begin(this);
            
        }



        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        protected virtual void Dispose(bool dispose)
        {
            if (dispose)
            {
                if (worker != null)
                {
                    worker.Dispose();
                    worker = null;
                }
            }
        }
    }
}
